﻿using ACC.Business.Stn;
using ACC.Business;
using ACC.Data;
using ACC.Data.Comm;
using ACC.Data.Line;
using ACC.Device;
using System;
using ACC.Data.Entities.Mes;
using System.Collections.Generic;
using ACC.Data.ACCLog;
using ACC.LineDevice.KukaPack;

namespace Script
{
    /// <summary>
    /// 绝缘板涂胶
    /// OP L1M02080 STATION L1M12081, L1M22081
    /// </summary>
    class L1M02080 : StnProcessPL02_DX
    {
        public L1M02080(StnRunningData data)
            : base(data)
        {
            IsReport = false;
            IsACCReport = false;
            IsPalletRelationSN = false;
        }

         protected override ACCDevice CreateDevice()
         {
             ACCDevice dev = base.CreateDevice();
             if (kukaSiemensDev != null)
             {
                 kukaSiemensDev.DB190 = 800;
                 kukaSiemensDev.DB190_Offset = 7000;
                 kukaSiemensDev.DB192 = 80;
                 kukaSiemensDev.DB192_PLC_Offset = 7290;

                 kukaSiemensDev.DB193 = 800;
                 kukaSiemensDev.DB193_PLC_Offset = 7034;
                 kukaSiemensDev.DB193_ACC_Offset = 7068;
                 kukaSiemensDev.DB194 = 800;
                 kukaSiemensDev.DB194_PLC_Offset = 7034;
                 kukaSiemensDev.DB194_PLC_Data_Offset = 7302;

                 kukaSiemensDev.BarcodeLength = 30;
                 kukaSiemensDev.LoadBarcodeCount = 2;
                 kukaSiemensDev.UnloadBarcodeCount = 2;
                 kukaSiemensDev.ProcessDataStringDataLength = 8;
                 //kukaSiemensDev.ProcessDataStringLength = 2;
                 //kukaSiemensDev.ProcessDataRealLength = 20;

                 kukaSiemensDev.Material_COMM_Offset = 292;       // 上下料信号位偏移量
             }

             return dev;

         }

         protected override void CreateBusinessLogic()
         {
             base.CreateBusinessLogic();

             (_loadProcess as LoadProcess_DX).R = 10;
             (_unloadProcess as UnloadProcess_DX).R = 10;
             (_unloadProcess as UnloadProcess_DX).S = 1;
             (_unloadProcess as UnloadProcess_DX).OneAsNG = true;
         }

         /// <summary>
         /// 从内存中移除（避免后面主线出现问题）
         /// </summary>
         /// <param name="dev"></param>
         /// <param name="result"></param>
         /// <returns></returns>
         public override ACCCode SendUnloadResult(ACCDevice dev, ACCDevice.UnloadResult result)
         {
             ACCCode rs = base.SendUnloadResult(dev, result);
             if (rs == ACCCode.ACCOK && result.ErrorCode == ACCCode.ACCOK)
             {
                 ACC.Business.Process.UnitDataProcess.RemoveWIPUnitFromLineCache(_lineData.RunningData, _data.LastUnloadUnit);
             }

             return rs;
         }
    }
}
